<template>
    <el-dialog class="dialog" :destroy-on-close="true" :title="title" :visible.sync="isShow" :close-on-click-modal="false"
        @close="onDialogClose">
        <el-form ref="form" label-width="auto" class="form" :model="formData" :rules="rules">
            <div style="display:flex">
                <span>
                    <el-form-item label="手机号" prop="remark">
                        <el-input :disabled="isEdit" v-model="formData.remark" placeholder="请输入手机号"
                            maxlength="11"></el-input>
                    </el-form-item>
                    <el-form-item label="姓名" prop="member_xm">
                        <el-input v-model="formData.member_xm" placeholder="请输入姓名" maxlength="20"></el-input>
                    </el-form-item>
                    <el-form-item label="性别" prop="member_xb">
                        <el-select v-model="formData.member_xb" placeholder="请选择性别">
                            <el-option v-for="item in sexData" :key="item.value" :label="item.label"
                                :value="item.value"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="身份证号" prop="id_num">
                        <el-input v-model="formData.id_num" placeholder="请输入身份证号" maxlength="18"></el-input>
                    </el-form-item>


                </span>
                <span style="margin-left:20px">
                    <el-form-item label="通行卡号" prop="door_card">
                        <el-input v-model="formData.door_card" placeholder="请输入通行卡号" maxlength="20"></el-input>
                    </el-form-item>
                    <el-form-item label="通行密码" prop="door_pwd">
                        <el-input v-model="formData.door_pwd" placeholder="请输入通行密码" minlength="4" maxlength="8"></el-input>
                    </el-form-item>
                    <el-form-item label="访客人脸" prop="face_thumb">
                        <uxUpload v-model="formData.face_thumb" dir="face/holder" :isPic="true"></uxUpload>
                    </el-form-item>
                </span>
            </div>
            <div style="display:flex">
                <el-form-item label="授权门禁" prop="door_arr">
                    <el-select multiple v-model="formData.door_arr" placeholder="请选择授权门禁">
                        <el-option v-for="item in passDoorData" :key="item.door_sn" :label="item.door_name"
                            :value="item.door_sn"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="有效期" prop="end_time" style="margin-left:20px">
                    <el-date-picker v-model="formData.end_time" type="date" value-format="yyyy-MM-dd"
                        placeholder="请选择有效期" :pickerOptions="pickerOptions"></el-date-picker>
                </el-form-item>
            </div>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="onDialogClose">取消</el-button>
            <el-button type="primary" @click="onSubmitBefore">确认</el-button>
        </div>
    </el-dialog>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { Action, State, Getter } from "vuex-class";
import { mixinDialogForm } from "@/mixin/dialog/Form";
import { mixinNext } from '@/mixin/Next';
import message from '@/utils/Message';
import uxUpload from "@/components/input/upload/index.vue";
@Component({
    mixins: [mixinDialogForm, mixinNext],
    components: { uxUpload }
})
export default class parkGuestEdit extends Vue {
    // 新增
    @Action("parkTenant/addGuest") itemAdd: any;
    // 编辑
    @Action("parkTenant/editGuest") itemEdit: any;

    @Action('equipmentDoor/passDoor') getPassDoor: any;
    @Getter("equipmentDoor/passDoor") passDoorData: any;
    mounted() {
        this.getPassDoor();
    }

    onSubmitBefore() {
        const me = this as any,
            formData = me.formData;
           // if(formData.door_arr.length > 0) {
             //   formData.door_arr =  formData.door_arr.join(",");
           // }
           
        if (formData.door_card == '' && formData.door_pwd == '' && formData.face_thumb == '') {
            message.show('卡号、密码、人脸 至少录入一项', 'error');
            return false;
        } else {
            me.onSubmit();
        }
    }

    @State((state) => state.sharing.sex) sexData: any;

    addInit() {
        const me = this as any;
        me.getPassDoor();
    }
    // 表单数据
    formData: any = {
        member_xm: "",
        member_xb: "1",
        remark: '',
        door_card: "",
        door_pwd: '',
        face_thumb: "",
        id_num: '',
        door_arr: '',
        end_time: ''

    };
    pickerOptions: any = {
        shortcuts: [
            {
                text: '一天',
                onClick(picker) {
                    const end = new Date();
                    end.setDate(end.getDate() + 1);
                    picker.$emit('pick', end);
                }
            },
            {
                text: '二天',
                onClick(picker) {
                    const end = new Date();
                    end.setDate(end.getDate() + 2);
                    picker.$emit('pick', end);
                }
            },
            {
                text: '三天',
                onClick(picker) {
                    const end = new Date();
                    end.setDate(end.getDate() + 3);
                    picker.$emit('pick', end);
                }
            },
            {
                text: '一周',
                onClick(picker) {
                    const end = new Date();
                    end.setDate(end.getDate() + 7);
                    picker.$emit('pick', end);
                }
            },
            {
                text: '一个月',
                onClick(picker) {
                    const end = new Date();
                    end.setMonth(end.getMonth() + 1);
                    picker.$emit('pick', end);
                }
            },
            {
                text: '三个月',
                onClick(picker) {
                    const end = new Date();
                    end.setMonth(end.getMonth() + 3);
                    picker.$emit('pick', end);
                }
            },
            {
                text: '六个月',
                onClick(picker) {
                    const end = new Date();
                    end.setMonth(end.getMonth() + 6);
                    picker.$emit('pick', end);
                }
            },
            {
                text: '一年',
                onClick(picker) {
                    const end = new Date();
                    end.setMonth(end.getMonth() + 12);
                    picker.$emit('pick', end);
                }
            }
        ]
    };

    /**
     * 校验配置
     *
     * @type {*}
     * @memberof mixinViewRules
     */
    rules: any = {
        member_xm: [
            {
                required: true,
                message: "请输入姓名",
                trigger: "blur"
            }
        ],
        member_xb: [
            {
                required: true,
                message: "请选择性别"
            }
        ],
        end_time: [
            {
                required: true,
                message: "请选择有效期",
                trigger: "blur"
            }
        ],
        door_arr: [
            {
                required: true,
                message: "请选择授权门禁",
                trigger: "blur"
            }
        ]
    };
    // 标题
    get title() {
        const title = (this as any).isEdit ? "编辑" : "新增";
        return `${title}访客`;
    }
}
</script>
